﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using KegData;

namespace KegManager
{
    public class TemperatureDisplay : DependencyObject
    {
        public static readonly DependencyProperty OneWireIdProperty = DependencyProperty.Register("OneWireId", typeof(string), typeof(TemperatureDisplay), new UIPropertyMetadata(""));
        public static readonly DependencyProperty NameProperty = DependencyProperty.Register("Name", typeof(string), typeof(TemperatureDisplay), new UIPropertyMetadata(""));
        public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(double), typeof(TemperatureDisplay), new PropertyMetadata(0.0));
        public static readonly DependencyProperty UpdateTimeProperty = DependencyProperty.Register("UpdateTime", typeof(DateTime), typeof(TemperatureDisplay));
        public static readonly DependencyProperty MaxAlertProperty = DependencyProperty.Register("MaximumAlert", typeof(double?), typeof(TemperatureDisplay), new PropertyMetadata(null));
        public static readonly DependencyProperty MinAlertProperty = DependencyProperty.Register("MinimumAlert", typeof(double?), typeof(TemperatureDisplay), new PropertyMetadata(null));

        public TemperatureDisplay(TemperatureLocation tl)
        {
            OneWireId = tl.OneWireId;
            Name = tl.Name;
            Value = 0.0;
            MaximumAlert = tl.MaximumAlert;
            MinimumAlert = tl.MinimumAlert;
        }

        public void Update(Temperature t)
        {
            Value = t.Value;
            UpdateTime = t.Time;
        }

        public string OneWireId
        {
            get { return (string)GetValue(OneWireIdProperty); }
            set { SetValue(OneWireIdProperty, value); }
        }

        public string Name
        {
            get { return (string)GetValue(NameProperty); }
            set { SetValue(NameProperty, value); }
        }

        public double Value
        {
            get { return (double)GetValue(ValueProperty); }
            set { SetValue(ValueProperty, value); }
        }

        public double? MaximumAlert
        {
            get { return (double?)GetValue(MaxAlertProperty); }
            set { SetValue(MaxAlertProperty, value); }
        }

        public double? MinimumAlert
        {
            get { return (double?)GetValue(MinAlertProperty); }
            set { SetValue(MinAlertProperty, value); }
        }
        public DateTime UpdateTime
        {
            get { return (DateTime)GetValue(UpdateTimeProperty); }
            set { SetValue(UpdateTimeProperty, value); }
        }
    }
}
